<?php
class CInfoMgr extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->model ( "CpyInfo" );
		$this->load->model ( "vo/CpyInfoVo" );
		$this->load->helper ( "form" );
	}
	
	function index($id = 1) {
		foreach ( $this->CpyInfo->getCpyInfoById ( $id, TRUE ) as $cpyObj ) {
			$this->CpyInfoVo->setCpyId ( $id );
			$this->CpyInfoVo->setCpyName ( $cpyObj->cpy_name );
			$this->CpyInfoVo->setCpyAddr1 ( $cpyObj->cpy_address_1 );
			$this->CpyInfoVo->setCpyAddr2 ( $cpyObj->cpy_address_2 );
			$this->CpyInfoVo->setCpyTel ( $cpyObj->cpy_tel );
			$this->CpyInfoVo->setCpyFax ( $cpyObj->cpy_fax );
			$this->CpyInfoVo->setCpyEmail ( $cpyObj->cpy_email );
			$this->CpyInfoVo->setCpyPhoto ( $cpyObj->cpy_photo );
			$this->CpyInfoVo->setCpyAu ( $cpyObj->cpy_au );
		}
		
		$data ['title'] = "Company Information";
		$data ['vo'] = $this->CpyInfoVo;
		$this->load->view ( "manager/updateInfo", $data );
	}
	
	function doUpdate() {
		$this->CpyInfoVo->setCpyId ( $this->input->post ( 'cpyId' ) );
		$this->CpyInfoVo->setCpyName ( $this->input->post ( 'cpyName' ) );
		$this->CpyInfoVo->setCpyAddr1 ( $this->input->post ( 'cpyAddr1' ) );
		$this->CpyInfoVo->setCpyAddr2 ( $this->input->post ( 'cpyAddr2' ) );
		$this->CpyInfoVo->setCpyTel ( $this->input->post ( 'cpyTel' ) );
		$this->CpyInfoVo->setCpyFax ( $this->input->post ( 'cpyFax' ) );
		$this->CpyInfoVo->setCpyEmail ( $this->input->post ( 'cpyEmail' ) );
		
		if ($this->input->post ( 'cpyAu' )) {
			$au = $this->input->post ( 'cpyAu' );
			$au = str_replace ( chr ( 13 ), '<br/>', $au );
			$au = str_replace ( chr ( 32 ), '&nbsp;', $au );
			
			$this->CpyInfoVo->setCpyAu ( $au );
		}
		
		$mess = "";
		if ($this->CpyInfoVo->getCpyId () == 0) {
			$this->CpyInfo->save ( $this->CpyInfoVo );
			$mess = "save success!";
		} else {
			$this->CpyInfo->update ( $this->CpyInfoVo );
			$mess = "update success!";
		}
		
		$data ['vo'] = $this->CpyInfo->getCpyInfoById ( 1 );
		$data ['title'] = "operater result";
		$data ['result'] = $mess;
		$data ['success'] = "true";
		$this->load->view ( "manager/updateResult", $data );
	}

}

?>